package com.cy.train.common.context;

import com.cy.train.common.resp.MemberLoginResp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @Description:
 * @Date: 2024/2/27 15:31
 * @Author: cyzhang
 */
public class LoginMemberContext {
    private static final Logger LOG = LoggerFactory.getLogger(LoginMemberContext.class);
    private static ThreadLocal<MemberLoginResp> threadLocal = new ThreadLocal<>();

    public static MemberLoginResp getMember() {
        return threadLocal.get();
    }

    public static void setMember(MemberLoginResp resp) {
        threadLocal.set(resp);
    }

    public static Long getId() {
        try {
            return threadLocal.get().getId();
        } catch (Exception e) {
            LOG.info("获取登录会员信息异常");
            throw e;
        }
    }
}
